﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TeamRanking
{
    public partial class Form1 : Form
    {
        RankingList rankedList = new RankingList();
        
        public Form1()
        {
            InitializeComponent(); 
        }

        private void addTeambutton_Click(object sender, EventArgs e)
        {
            Team team = new Team();
            getTeamInfo(team);
            rankedList.AddTeam(team);
            List<Team> teamsByRank = rankedList.RankTeams();
            clearFormEntries();
            ranklistBox.Items.Clear();
            displayListOfTeams(teamsByRank);
        }

        private void getTeamInfo(Team team)
        {
            team.Name = teamNameTextBox.Text;
            team.Wins = (int)numericUpDownWins.Value;
            team.Losses = (int)numericUpDownLosses.Value;
            team.Ties = (int)numericUpDownTies.Value;
            team.Points = (int)numericUpDownTotalPoints.Value;
            team.PointsAllowed = (int)numericUpDownPointsAllowed.Value;
            team.OffensiveYards = (double)numericUpDownOffensiveYards.Value;
            team.DefensiveYards = (double)numericUpDownDefensiveYards.Value;
        }
        
        private void displayListOfTeams(List<Team> teamList)
        {
            for (int t = 0; t != rankedList.NumberofTeams; t++)
            {
                ranklistBox.Items.Add(
                    teamList[t].Rank.ToString() + ".  " +
                    teamList[t].Name.ToString() + " (" +
                    teamList[t].Wins.ToString() + " - " +
                    teamList[t].Losses.ToString() + " - " +
                    teamList[t].Ties.ToString() + ")");
            }
        }

        private void clearFormEntries()
        {
            teamNameTextBox.Text = "";
            numericUpDownWins.Value = 0;
            numericUpDownLosses.Value = 0;
            numericUpDownTies.Value = 0 ;
            numericUpDownTotalPoints.Value = 0;
            numericUpDownPointsAllowed.Value = 0;
            numericUpDownOffensiveYards.Value = 0;
            numericUpDownDefensiveYards.Value = 0;
            teamNameTextBox.Focus();
        }
    }
}
